package _04_priorityQueue;

// 进程类，由“（进程名，优先级）”组成，按优先级比较大小
public class Process implements Comparable<Process> {
    
    // 进程名
    private String name;
    // 优先级
    private int priority;
    // 优先级最大值，优先级范围为1~MAX_PRIORITY
    private static int MAX_PRIORITY = 10;
    
    // 构造进程，参数name、priority分别指定进程名和优先级，优先级超出范围时抛出无效参数异常
    public Process(String name, int priority) {
        this.name = name;
        if (priority >= 1 && priority <= MAX_PRIORITY) {
            this.priority = priority;
        } else {
            throw new IllegalArgumentException("priority = " + priority);
        }
    }
    
    public Process(String name) {
        this(name, 5);
    }
    
    public String toString() {
        return "(" + this.name + ", " + this.priority + ")";
    }
    
    @Override
    // 进程按优先级比较大小
    public int compareTo(Process process) {
        // TODO Auto-generated method stub
        return this.priority - process.priority;
    }
    
    public static void main(String[] args) {
        // TODO Auto-generated method stub

    }

}
